//
//  StarEffectObject.m
//  TowerDefence
//
//  Created by k3 on 6/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "SkillEffectObject.h"
#import "iCoreGUIController.h"


@implementation SkillEffectObject

-(id)initStarEffectObjectWith:(GameLayer *)_gameLayer{
    self = [super initGameObjectWith:_gameLayer];
    spriteBody = [[CCSprite alloc]init];
    return self;
}

-(void)moveStarEffectOnMapWith:(CGPoint)_point{
    pointOnMap = _point;
    CCAnimation *animation = [handler.mainGUIController loadAnimationFromCacheByName:@"star_effect" withCount:24 delay:0.125];
    CCCallFunc *functionRemove = [CCCallFunc actionWithTarget:self selector:@selector(removeAllEffect)];
    [spriteBody runAction:[CCSequence actions:[CCMoveTo actionWithDuration:0.75 position:pointOnMap],[CCAnimate actionWithAnimation:animation],functionRemove, nil]];
}

-(void)moveThunderLightOnMap:(CGPoint)_point {
    pointOnMap = _point;
    CCAnimation *animation = [handler.mainGUIController loadAnimationFromCacheByName:@"thunder_light_effect" withCount:24 delay:0.125];
    CCCallFunc *functionRemove = [CCCallFunc actionWithTarget:self selector:@selector(removeAllEffect)];
    [spriteBody runAction:[CCSequence actions:[CCMoveTo actionWithDuration:0.75 position:pointOnMap],[CCAnimate actionWithAnimation:animation],functionRemove ,nil]];

}

-(void)removeAllEffect {
    [self.spriteBody removeFromParentAndCleanup:YES];
}

-(float)randomFloatBetween:(float)smallNumber and:(float)bigNumber {
    float diff = bigNumber - smallNumber;
    return (((float) (arc4random() % ((unsigned)RAND_MAX + 1)) / RAND_MAX) * diff) + smallNumber;
}


-(void)moveAnimationWithFrameName:(NSString *)_frameName frameCount:(int)_frameCount {
    NSMutableArray *arrayFrame = [self loadAnimationWithNumberOfFrames:_frameCount withFrameName:_frameName];
    CCAnimation *animation = [CCAnimation animationWithFrames:arrayFrame delay:0.075];
    
    [spriteBody runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO]]];
}


@end
